import { reqCategoryList, reqGetBannerList ,reqGetFloorList} from "@/api";

export default ({
    // state:仓库存储数据的地方
    state: {
        categoryList: [],
        bannerList: [],
        floorList: []
    },
    // mutations：修改state的唯一手段
    mutations: {
        CATEGORYLIST(state, categoryList) {
            state.categoryList = categoryList;
        },
        GETBANNERLIST(state, bannerList) {
            state.bannerList = bannerList;
        },
        GETFLOORLIST(state, floorList) {
            state.floorList = floorList;
        }
    },
    // actions：处理actions，可以书写自己的业务逻辑，也可以处理异步
    actions: {
        // 通过API里面的接口函数调用，向服务器发送请求，获取服务器的数据
        async categoryList({ commit }) {
            let result = await reqCategoryList();
            if (result.code == 200) {
                commit("CATEGORYLIST", result.data);
                console.log('categoryList',result.data)
            }
        },
        // 获取轮播图的数据（mock模拟请求）
        async getBannerList({ commit }) {
            let result = await reqGetBannerList();
            if (result.code == 200) {
                commit("GETBANNERLIST", result.data);
            }
            console.log('轮播图数据',result)
        },
        async getFloorList({ commit }) {
            let result = await reqGetFloorList();
            console.log('test',result);
            if (result.code == 200) {
                console.log('test')
                commit("GETFLOORLIST", result.data);
            }
        }
    },
    // 理解为计算属性，用于简化仓库数据，让组件获取仓库库的数据更加方便
    getters: {},
})